package com.android.equipment.dao.operate;

import com.android.equipment.ObjectBox;
import com.android.equipment.dao.Work;
import com.android.equipment.dao.Work_;

import java.util.List;

import io.objectbox.Box;

public class DaoWork {
    static Box<Work> workBox;
    private static DaoWork instance;

    private DaoWork() {
    }

    public static DaoWork getInstance() {
        if (instance == null) {
            instance = new DaoWork();
            workBox = ObjectBox.get().boxFor(Work.class);
        }
        return instance;
    }

    public List<Work> getAll() {
        return workBox.query().orderDesc(Work_.id).build().find();
    }

    //根据状态查询出相应的工作
    public List<Work> getWorkByWorkStatus(int status) {
        return workBox.query().equal(Work_.status, status).build().find();
    }

    public void addWork(Work work) {
        workBox.put(work);
    }

    public void delWork(Work work) {
        long workId = work.getId();
        workBox.remove(work);
    }
    public Work getWork(long id) {
        return workBox.get(id);
    }

    public void updateWork(Work work) {
        workBox.put(work);
    }
}
